package cn.wolfcode.luowowo.hotel.service.impl;

import cn.wolfcode.luowowo.hotel.domain.HotelThemeCity;
import cn.wolfcode.luowowo.hotel.mapper.HotelThemeCityMapper;
import cn.wolfcode.luowowo.hotel.query.HotelThemeCityQueryObject;
import cn.wolfcode.luowowo.hotel.service.IHotelThemeCityService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 酒店主题
 *
 * @author win
 */
@Service
public class HotelThemeCityServiceImpl implements IHotelThemeCityService {

    @Autowired
    private HotelThemeCityMapper hotelThemeCityMapper;

    @Override
    public void deleteById(Long id) {
        hotelThemeCityMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void saveOrUpdate(HotelThemeCity theme) {
        if (theme == null) {
            return;
        }
        if (theme.getId() == null) {
            hotelThemeCityMapper.insert(theme);
        } else {
            hotelThemeCityMapper.updateByPrimaryKey(theme);
        }
        // TODO 后续维护关系
    }

    @Override
    public HotelThemeCity findById(Long id) {
        return hotelThemeCityMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<HotelThemeCity> selectAll() {
        return hotelThemeCityMapper.selectAll();
    }

    @Override
    public PageInfo<HotelThemeCity> query(HotelThemeCityQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        return new PageInfo<>(hotelThemeCityMapper.selectForList(qo));
    }

    @Override
    public List<HotelThemeCity> queryTop6ByThemeId(Long themeId) {
        return hotelThemeCityMapper.selectTop6(themeId);
    }
}
